#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPixmap>
#include <QTimer>
#include <QPainter>
#include <iostream>
#include <shape.h>

using namespace std;


QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

    struct BarrierBlock
    {
        BarrierBlock(const QBrush &b = QColor(255,255,255),const bool &is = false):brush(b),isBarrier(is){}
        QBrush brush;
        bool isBarrier;
    };

public:
    Widget(QWidget *parent = nullptr);
    ~Widget() override;
    void Connect();
    void createGamePixmap();
    void mouseMoveEvent(QMouseEvent *Event) override;
    void mouseReleaseEvent(QMouseEvent *) override;
    void keyPressEvent(QKeyEvent *event) override;
    void keyReleaseEvent(QKeyEvent *event) override;
    void setMyShape();
    void getRandShape();
    void drawCurShape();
    bool cannotDown();
    void addcurShapeToBarrier();
    bool cannotLeft();
    bool cannotRight();
    void DealfullLine();
    bool isFail();
    bool isInBerrier();
    void drawBlock(QPixmap& pixmap, const QPoint &p, bool isShapeStyle=true);
    bool isBarrier(const QPoint &p);
    BarrierBlock &recurBlock(int x,int y);
private:
    Ui::Widget *ui;
    QPixmap *gamePixmap = nullptr;
    const int widthNum = 15;
    const int heightNum = 25;
    const QSize blockSize = {30,30};
    QPointF curMousePos;
    bool isWinMove = false;
    QTimer *timer = new QTimer;
    const int mse = 500;
    double runTime = 0.0;
    vector<Shape> myShape;
    Shape *curShape = nullptr;
    QBrush blockBrush;
    vector<BarrierBlock> theBarrier;
    int score = 0;
};
#endif // WIDGET_H
